home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / tools / czesc_2 / ispell-3.3ljr / ispell / amiga.c next >
C/C++ Source or Header  |  1992-09-22  |  4KB  |  191 lines

  1. /*
  2.  *  Deal w/ amiga console screen stuff (and other missing stuff - LJR).
  3.  *
  4.  *                    -- luis soltero, 5/12/88 --
  5.  *
  6.  *  Total rework by Loren J. Rittle, 12/28/90
  7.  *
  8.  *  Now when ISpell is run in interactive mode, all screen
  9.  *  I/O is directed at the CLI window ISpell is started in 
  10.  *  if possible.  If started by WorkBench then, of course,
  11.  *  a window is opened for screen I/O.
  12.  *
  13.  *  Note: None of the screen I/O routines are called if ISpell
  14.  *  is run in ARexx server mode.
  15.  */
  16.  
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <stdarg.h>
  20. #include <string.h>
  21. #include <fcntl.h>
  22. #include <signal.h>
  23. #pragma msg 148 ignore push
  24. #pragma msg 149 ignore push
  25. #pragma msg 61 ignore push
  26. #include <exec/types.h>
  27. extern struct DosLibrary *DOSBase ;
  28. #include <dos/dos.h>
  29. #include <dos/dosextens.h>
  30. #include <clib/dos_protos.h>
  31. #include <pragmas/dos_pragmas.h>
  32. #include <intuition/intuition.h>
  33. #include <clib/intuition_protos.h>
  34. #include <pragmas/intuition_pragmas.h>
  35. #pragma msg 149 pop
  36. #pragma msg 61 pop
  37. #include "version.h"
  38. #include "ispell.h"
  39.  
  40. BPTR tty;
  41.  
  42. struct colortype
  43. {
  44.   char *style;
  45.   char *frw;
  46.   char *bak;
  47. } colors[] =
  48. {
  49. #define WHITE_ON_BLACK    0
  50.   {"0", "31", "42"},
  51. #define WHITE_ON_BLUE    1
  52.   {"0", "31", "40"},
  53. #define BLACK_ON_WHITE    2
  54.   {"0", "32", "41"},
  55. #define BLUE_ON_WHITE    3
  56.   {"0", "30", "41"},
  57. #define ORANGE_ON_BLUE    4
  58.   {"0", "33", "40"},
  59. #define BLUE_ON_ORANGE  5
  60.   {"0", "30", "43"}
  61. };
  62.  
  63. #define SETCOLORS(x)    (setcolors(colors[x].style, colors[x].frw, colors[x].bak))
  64.  
  65. void setcolors (char *style, char *fg, char *bg)
  66. {
  67.   char buf[16];
  68.  
  69.   sprintf (buf, "\x9b%s\x3b%s\x3b%s\x6d", style, fg, bg);
  70.   Write (tty, buf, strlen(buf));
  71. }
  72.  
  73. void printcon (char *fmt,...)
  74. {
  75.   char buf[256];
  76.   va_list ap;
  77.  
  78.   va_start (ap, fmt);
  79.   vsprintf (buf, fmt, ap);
  80.   va_end (ap);
  81.   Write (tty, buf, strlen(buf));
  82. }
  83.  
  84. void putccon (int ch)
  85. {
  86.   char c = ch;
  87.  
  88.   Write (tty, &c, 1);
  89. }
  90.  
  91. int getccon (void)
  92. {
  93.   unsigned char ch;
  94.  
  95.   Read(tty, &ch,1L);
  96.   return ((int)ch);
  97. }
  98.  
  99. /* This subroutine does the work of turning the current console to raw  */
  100. /* Pass a zero to turn it to cooked mode, any other value to turn it    */
  101. /* to raw mode.                                                         */
  102. int rawmode (int flag)
  103. {
  104.   return SetMode (Output (), flag);
  105. }
  106.  
  107. /* open a console window for ISpell */
  108. void terminit (void)
  109. {
  110.   tty = Open("*", MODE_OLDFILE);
  111.   rawmode(1);
  112.   li = 23;
  113.   co = 77;
  114. }
  115.  
  116. void done (void)
  117. {
  118.   remove (tempfile);
  119.   Close(tty);
  120.   rawmode(0);
  121.   exit (0);
  122. }
  123.  
  124. /* clear the screen */
  125. void erase (void)
  126. {
  127.   Write (tty, "\x0c", 1);
  128. }
  129.  
  130. /* move to row, col */
  131. void move (int row, int col)
  132. {
  133.   char buf[16];
  134.  
  135.   sprintf (buf, "\x9b%d\x3b%d\x48", row, col);
  136.   Write (tty, buf, strlen(buf));
  137. }
  138.  
  139. /* do stand out mode */
  140. void inverse (void)
  141. {
  142.   SETCOLORS (BLUE_ON_WHITE);
  143. }
  144.  
  145. /* do stand end mode */
  146. void normal (void)
  147. {
  148.   SETCOLORS (WHITE_ON_BLUE);
  149. }
  150.  
  151. /* do a back space */
  152. void backup (void)
  153. {
  154.   putccon ('\b');
  155. }
  156.  
  157. /* not implemented on the amiga */
  158. void onstop (int signo)
  159. {
  160. }
  161.  
  162. void stop (void)
  163. {
  164. }
  165.  
  166. /*
  167.  * i really do not understand why sleep is used in Ispell. Here is a null
  168.  * function used soley to keep ispell happy.
  169.  */
  170. /* i do.  fixed.  -tgr */
  171. void sleep (int n)
  172. {
  173.   if (n > 0)
  174.     Delay (50L * n);
  175. }
  176.  
  177. /*
  178.  * This function is broken in SAS/C v5.10 - LJR 
  179.  * Thanks to Matt Dillon, as this was lifted from DICE. 
  180.  */
  181. char *tmpnam(char *buf)
  182. {
  183.     static char Buf[32];
  184.     static long i;
  185.  
  186.     if (buf == NULL)
  187.     buf = Buf;
  188.     sprintf(buf, "T:%08lx-%ld", FindTask(NULL), i++);
  189.     return(buf);
  190. }
  191.